<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><li class="fa fa-remove"></li></button>
    <h5 class="modal-title"></h5>
</div>

<div class="modal-body">
    <form id="sensor_form" name="sensor_form" class="form-horizontal">
        <input type="hidden" name="id">
        <input type="hidden" id="deviceId" name="deviceId" value="${deviceId}">
        <input type='hidden' value="${CSRFToken}" id='csrftoken'>
        <div class="box-body">
            <div class="col-md-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">传感器<span style="color:red">&nbsp;*</span></label>
                    <div class="col-sm-8">
                        <select name="type.id" id="type.id" title="民族" data-flag="dictSelector" data-code="DEVICE" data-placeholder="请选择传感器" class="form-control select2" style="width:100%" data-blank="true"></select>
                    </div>
                </div>
                
                
                <div class="form-group">
                    <label class="col-sm-3 control-label">IO端口</label>
                    <div class="col-sm-8">
                        <input type="text" class="form-control" id="ioPort" name="ioPort" placeholder="不填将采用默认值">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">取值精度</label>
                    <div class="col-sm-8">
                        <input type="text" class="form-control" id="livalue" name="livalue" placeholder="不填将采用默认值">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">单位</label>
                    <div class="col-sm-8">
                        <input type="text" class="form-control" id="unit" name="unit" placeholder="不填将采用默认值">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">备注</label>
                    <div class="col-sm-8">
                        <input type="text" class="form-control" id="remark" name="remark" placeholder="备注信息">
                    </div>
                </div>
            </div>
        </div>
        <div class="box-footer text-right">
            <button type="button" class="btn btn-default" data-btn-type="cancel" data-dismiss="modal">取消</button>
            <button type="submit" class="btn btn-primary" data-btn-type="save">提交</button>
        </div>
    </form>
</div>
<script>
    var form;
    var id="${id?default(0)}";
    $(function(){
        //初始化表单
        form=$("#sensor_form").form();
        //数据校验
        $("#sensor_form").bootstrapValidator({
            message : '请输入有效值',
            feedbackIcons : {
                valid : 'glyphicon glyphicon-ok',
                invalid : 'glyphicon glyphicon-remove',
                validating : 'glyphicon glyphicon-refresh'
            },
            submitHandler : function() {
                modals.confirm('确认保存？', function() {
                    var sensor = form.getFormSimpleData();
                    ajaxPost(basePath+'/device/saveSensor',{"obj":JSON.stringify(sensor)}, function(data) {
                        if(data.success){
                        	modals.hideWin(swinId);
                        	sensorTable.reloadData();
                        }
                    });
                });
            },
            fields : {
                "type":{
                    validators:{
                        notEmpty:{message:'传感器不能为空'}
                    }
                }
            }
        });
        //初始化控件
        form.initComponent();
        //编辑回填
        if(id!=0){
            ajaxPost(basePath+"/device/getSensor/"+id,null,function(data){
                form.initFormData(data);
            })
        }
    });
</script>
